﻿//-----------------------------------------------------------------------
// <copyright file="UsageWebRequest.cs" company="Redmist">
//     Copyright (c) Damien T Smith. All rights reserved.
// </copyright>
// <author>Damien Smith</author>
//-----------------------------------------------------------------------

namespace Redmist.UsageMonitor.WebIO
{
    using System.IO;
    using System.Net;

    /// <summary>An implementation of Redmist.UsageMonitor.WebIO.IHttpWebRequest using System.Net.HttpWebRequest.</summary>
    public class UsageWebRequest : IHttpWebRequest
    {
        /// <summary>A System.Net.HttpWebRequest used for making requests to HTTP resources.</summary>
        private HttpWebRequest httpWebRequest;

        /// <summary>Initializes a new instance of the UsageWebRequest class.</summary>
        /// <param name="httpWebRequest">A System.Net.HttpWebRequest used for making requests to HTTP resources.</param>
        public UsageWebRequest(HttpWebRequest httpWebRequest)
        {
            this.httpWebRequest = httpWebRequest;
        }

        /// <summary>Gets or sets a System.Net.CookieContainer representing a container of HTTP cookies.</summary>
        public CookieContainer CookieContainer { get; set; }

        /// <summary>Gets a System.IO.Stream object to use to write request data.</summary>
        /// <returns>A System.IO.Stream to use to write request data.</returns>
        public Stream GetRequestStream()
        {
            return this.httpWebRequest.GetRequestStream();
        }

        /// <summary>Returns a response from an HTTP resource.</summary>
        /// <returns>A Redmist.UsageMonitor.WebIO.IHttpWebResponse containing a response from a HTTP resource.</returns>
        public IHttpWebResponse GetResponse()
        {
            return new UsageWebResponse((HttpWebResponse)this.httpWebRequest.GetResponse());
        }
    }
}
